#include "../../mqserver/msgqueue.hpp"
#include "../../mqcommon/msg.pb.h"
#include <gtest/gtest.h>

std::shared_ptr<MsgQueueManager> managerPtr;
class MsgQueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        managerPtr = std::make_shared<MsgQueueManager>("ccc/data.db");
    }
    virtual void TearDown() override
    {
        managerPtr->clear();
    }
};

// TEST(MsgQueueTest, declareMsgQueueTest)
// {
//     std::unordered_map<std::string, std::string> mp{{"k1", "v1"},{"k2", "v2"}};
//     managerPtr->declareMsgQueue("msgqueue1", true, false, false, mp);
//     managerPtr->declareMsgQueue("msgqueue2", true, false, false, mp);
//     managerPtr->declareMsgQueue("msgqueue3", true, false, false, mp);
//     managerPtr->declareMsgQueue("msgqueue4", true, false, false, std::unordered_map<std::string, std::string>());
//     EXPECT_EQ(managerPtr->size(), 4);
// }
TEST(MsgQueueTest, deleteMsgQueueTest)
{
    managerPtr->deleteMsgQueue("msgqueue1");
    EXPECT_EQ(managerPtr->size(), 3);
}
TEST(MsgQueueTest, selectMsgQueueTest)
{
    MsgQueue::Ptr pMsgQueue = managerPtr->selectMsgQueue("msgqueue2");
    EXPECT_EQ(pMsgQueue->name, "msgqueue2");
    EXPECT_EQ(pMsgQueue->durable, true);
    EXPECT_EQ(pMsgQueue->exclusive, false);
    EXPECT_EQ(pMsgQueue->autoDelete, false);
    // EXPECT_EQ(exchangePtr->serializeArgs(), "k1=v1;k2=v2;");
    // EXPECT_EQ(exchangePtr->serializeArgs(), "k2=v2;k1=v1;");        //这个变来变去的
}
int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MsgQueueTest);

    return RUN_ALL_TESTS(); 
}